//
//  KeypairDelegate.m
//  cTypica
//
//  Created by David Kavanagh on 11/25/08.
//  Copyright 2008 directThought. All rights reserved.
//

#import "KeypairDelegate.h"
#import "KeypairInfo.h"

@implementation KeypairDelegate
@synthesize keypairs;

+ (id)delegate {
	KeypairDelegate *ret = [self alloc];
	return ret;
}

// XML parser delegate methods
- (void)parser: (NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
	if ([elementName isEqualToString:@"keySet"]) {
		self.keypairs = [[NSMutableArray alloc] initWithCapacity:1];
	}
	else if ([elementName isEqualToString:@"item"]) {
		item = [KeypairInfo alloc];
		
	}
}

- (void)parser: (NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
	NSString *cleanString = [currentStringValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
	[currentStringValue setString:@""];
	if ([elementName isEqualToString:@"keySet"]) {
	}
	else if ([elementName isEqualToString:@"item"]) {
		[self.keypairs addObject:item];
		[item release];
		item = nil;
	}
	else if ([elementName isEqualToString:@"keyName"]) {
		item.keyName = cleanString;
	}
	else if ([elementName isEqualToString:@"keyFingerprint"]) {
		item.keyFingerprint = cleanString;
	}
	
}
@end
